'''
1. initialized info of bank card
2. log in
3. search balance
4. draw money
5. withdraw money
6. log out
7. interface and interaction
'''

# 1. info of bank card
card_info = [
    {'accountName': 'card1', 'password': '1', 'cardNumber': '111111111', 'balance': '20001'},
    {'accountName': 'card2', 'password': '2', 'cardNumber': '111111112', 'balance': '20002'}
]


# 2. log in system
def logIn_atm(accountName, password):
    for name in card_info:
        if accountName == name['accountName']:
            if password == name['password']:
                print('登陆成功')
                return True
            else:
                print('用户名密码错误，请重新输入')
                return False
    print('用户名不存在，请注册')
    return False


# 3. show balance of ur card
def show_balance(accountName):
    for name in card_info:
        if accountName == name['accountName']:
            account_balance = name['balance']
            return account_balance
    pass


# 4. withdraw money
def widthdraw_money(accountName, money):
    if money > 0:
        for name in card_info:
            if accountName == name['accountName']:
                newBalance = int(name['balance']) - money
                name['balance'] = newBalance
                return name['balance']
    pass


# 5. draw money
def draw_money(accountName, money):
    if money > 0:
        for name in card_info:
            if accountName == name['accountName']:
                newBalance = int(name['balance']) + money
                name['balance'] = newBalance
                return name['balance']
    pass


# 6. log out system
def logout_atm():
    pass


# 7. interface and interaction
while True:

    print('=' * 12, '欢迎来到ATM机管理系统,请登陆', '=' * 12)
    account_name = input('请输入用户名:').strip()
    pass_Word = input('请输入密码:').strip()
    if logIn_atm(account_name, pass_Word):
        print('=' * 12, '欢迎来到ATM机管理系统', '=' * 12)
        print('{:5}\t{:<13}\t{:<15}'.format(' ', '1.查询余额', '2.取现'))
        print('{:5}\t{:<13}\t{:<15}'.format(' ', '3.存储现金', '4.退出登陆'))
        print('=' * 47)
        while True:
            key = int(input('请输入所需要的操作:'))
            if key == 1:
                my_balance = show_balance(account_name)
                print('')
                print('"', account_name, '" 先生/女士，您好！您的账户及余额如下：')
                print('{:5}\t|\t{:5}'.format('账号', '余额'))
                print('{:5}\t|\t{:5}'.format(account_name, my_balance))
                print('')
                print('-' * 47)
            if key == 2:
                withdraw = int(input('请输入要取出的金额：'))
                new_balance = widthdraw_money(account_name, withdraw)
                print('')
                print('"', account_name, '" 先生/女士，您好！现金已取出，您的账户及余额如下：')
                print('{:5}\t|\t{:5}'.format('账号', '余额'))
                print('{:5}\t|\t{:5}'.format(account_name, new_balance))
                print('')
                print('-' * 47)
            if key == 3:
                withdraw = int(input('请输入要存储的金额：'))
                new_balance = draw_money(account_name, withdraw)
                print('')
                print('"', account_name, '" 先生/女士，您好！现金已存入您的账户，您的账户及余额如下：')
                print('{:5}\t|\t{:5}'.format('账号', '余额'))
                print('{:5}\t|\t{:5}'.format(account_name, new_balance))
                print('')
                print('-' * 47)
            if key == 4:
                print('系统退出成功')
                print('-' * 47)
                print('')
                break

